package com.example.gouwu2;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;


public class StartActivity extends AppCompatActivity {

    private ImageView ivStartImg;
    private TextView textView;
    private static final long SPLASH_DELAY = 1500; // 延时 3 秒（可调整）

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        // 1. 初始化控件
        ivStartImg = findViewById(R.id.start_img);
        textView = findViewById(R.id.View);

        // 2. 启动倒计时（可选，给用户提示）
        startCountdown();

        // 3. 延时跳转逻辑
        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            jumpToNextActivity();
        }, SPLASH_DELAY);
    }

    private void startCountdown() {
        int totalSeconds = (int) (SPLASH_DELAY / 1000);
        new CountDownTimer(SPLASH_DELAY, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                int remainingSeconds = (int) (millisUntilFinished / 1000);
               textView.setText(remainingSeconds + " 秒后跳转");
            }

            @Override
            public void onFinish() {
                textView.setText("正在跳转...");
            }
        }.start();
    }
    
    private void jumpToNextActivity() {
        Intent intent = new Intent(StartActivity.this, RegisterActivity.class);
        startActivity(intent);
        finish(); // 关闭当前启动页，避免返回
    }
}